/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bean.timer.interfaces;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import javax.swing.JPanel;

/**
 *
 * @author sammael
 */
public abstract class AbstractTimer extends JPanel implements AbstractTimerControl,AbstractTimeView,AbstractTimerModel{

    long limit;
    AtomicLong atomicCurrentTime;
    //volatile long currentTime;
    int tickLengh;
    int warningTicksCount;
    List<TimerListener> listeners = new ArrayList<>();
    boolean countingDown;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Clock clock = new Clock();

    public AbstractTimer() {
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
               executor.shutdownNow();
               }
            })
        );
    }
    
    
    
    @Override
    public void setLimit() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public long getLimit() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setLimit(long limit) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean isCountingDown() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setCountingDown(boolean countingDown) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public long getCurrentTime() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setCurrentTime(long time) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setWarningTicksCount(int ticks) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getWarningTicksCount() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setTickLength(int milisec) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getTickLength() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addTimerListener(TimerListener listener) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeTimerListener(TimerListener listener) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public TimerListener[] getTimerListeners() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    public final class Clock implements Runnable{
        private boolean stop;
        public void stop(){
            stop = true;
        }
        @Override
        public void run() {
            stop = false;
            while(!stop){
                try{
                    Thread.sleep(100);
                    atomicCurrentTime.getAndAdd(100);
                }catch(InterruptedException e){
                }
            }
        }
        
    }
}
